package com.gpay.erp.services.sales.impl;

import com.gpay.erp.core.dao.BaseDao;
import com.gpay.erp.core.dao.page.PagerModel;
import com.gpay.erp.services.sales.StorageResourceService;
import com.gpay.erp.services.sales.bean.ResourceListing;
import com.gpay.erp.services.sales.bean.StorageResource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2015/9/9 0009.
 */
@Service
public class StorageResourceServiceImpl implements StorageResourceService {
	@Resource
	private BaseDao dao;

	public int insert(StorageResource storageResource) {
		return dao.insert("storageResource.insert", storageResource);
	}

	public int delete(StorageResource storageResource) {
		return 0;
	}

	public int deletes(String[] ids) {
		return 0;
	}

	public int update(StorageResource storageResource) {
		int id = dao.update("storageResource.updateByStatus1", storageResource);
		if (storageResource.getListingNumber() != null
				&& storageResource.getListingPrice() != null
				&& storageResource.getStatus().equals("1")) {
			storageResource.setRes_id(id + "");
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
			storageResource.setListingTime(df.format(new Date()));
			return dao.insert("storageResource.insert2", storageResource);
		}
		if (storageResource.getStatus().equals("0")) {
			storageResource.setRes_id(id + "");
			return dao.delete("storageResource.deleteListing", storageResource);
		}
		return id;
	}

	public StorageResource selectOne(StorageResource storageResource) {
		return null;
	}

	public StorageResource selectById(String id) {
		return null;
	}

	public PagerModel selectPageList(StorageResource storageResource) {
		if (storageResource.getFlag().equals("selectStorageAllResource")) {
			return dao.selectPageList("storageResource.selectPageList",
					"storageResource.dataTotal", storageResource);
		}
		if (storageResource.getFlag().equals("selectStorageResource")) {
			storageResource.setStatus("0");
			storageResource.setStatus2("1");
			return dao.selectPageList("storageResource.selectPageList",
					"storageResource.dataTotal", storageResource);
		}
		if (storageResource.getFlag().equals("selectResourceListing")) {
			storageResource.setStatus("1");
			return dao.selectPageList("storageResource.selectPageList1",
					"storageResource.dataTotal1", storageResource);
		}
		return null;
	}

	public List<StorageResource> selectList(StorageResource storageResource) {
		return null;
	}

}
